
<!--主界面-->

<template>
  <div>
    <el-container style="min-height: 100vh;">
<!--      左导航栏-->
      <el-aside :width="sideWidth + 'px'" style="background-color: rgb(238, 241, 246); box-shadow: 2px 0 6px rgba(0, 20, 41,0.4);">
        <BossmanAside :isCollapse="isCollapse" :logoTextShow="logoTextShow" />
      </el-aside>

<!--      头部导航栏-->
      <el-container>
        <el-header style="height: 70px; border-bottom: 1px solid #ccc; padding: 0 10px;">
          <BossmanHeader :collapseBtnClass="collapseBtnClass" :collapse="collapse" :user="user" />
        </el-header>

<!--        页面导航栏-->
        <el-main style="height:300px ">
          <router-view @refreshUser="init" />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import BossmanAside from "@/components/BossmanAside.vue";
import BossmanHeader  from "@/components/BossmanHeader.vue";
import {getUserByUsername} from "@/api/user";

export default {
  name: "Bossman",
  data() {
    return {
      collapseBtnClass: "el-icon-s-fold",
      //展开与收缩
      isCollapse: false,
      sideWidth: 200,
      logoTextShow: true,
      user: {},
    }
  },
  components: {
    BossmanAside,
    BossmanHeader,
  },
  created() {
    this.init()
  },
  methods: {
    collapse() {//点击收缩按钮触发
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) {//收缩
        this.sideWidth = 64
        this.collapseBtnClass = 'el-icon-s-unfold'
        this.logoTextShow = false
      } else {//展开
        this.sideWidth = 200
        this.collapseBtnClass = 'el-icon-s-fold'
        this.logoTextShow = true
      }
    },
    init() { // 初始化用户信息
      let username = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')).username : ""
      getUserByUsername(username).then(res => {
        // 重新赋值最新用户信息
        this.user = res
})
    },
  }
}
</script>

<style scoped>

</style>